package com.atguigu.lease.web.admin.custom.config;

import com.atguigu.lease.web.admin.custom.converter.StringToBaseEnumConverterFactory;
import com.atguigu.lease.web.admin.custom.converter.StringToItemTypeConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebMvcConfiguration implements WebMvcConfigurer {

    //数据类型转换：前端参数经过WebDataBinder(SpringMVC)绑定到controller的方法参数上
    //TypeHandler(Mybatisplus)用于处理java中的实体类对象和数据库之间的数据类型转换
    //HTTPMessageConverter(SpringMVC)负责将controller方法的返回值转换成http响应体中的json字符串，
    //或者将http请求体中的json字符串转换成controller的方法参数

    @Autowired
    private StringToBaseEnumConverterFactory stringToBaseEnumConverterFactory;

    @Override
    public void addFormatters(FormatterRegistry registry) {
        registry.addConverterFactory(this.stringToBaseEnumConverterFactory);
    }

}
